package com.lordjoe.collectiveintelligence.svm;

import libsvm.*;

/**
 * com.lordjoe.collectiveintelligence.svm.matchmaker.AbstractSVMDataWarpper
 *
 * @author Steve Lewis
 * @date May 25, 2009
 */
public abstract class AbstractSVMDataWrapper<T> implements ISVMDataItem
{
    public static AbstractSVMDataWrapper[] EMPTY_ARRAY = {};
    public static Class THIS_CLASS = AbstractSVMDataWrapper.class;

    private final T m_Data;

    public AbstractSVMDataWrapper(T in)
    {
        m_Data = in;
    }

    public T getData()
    {
        return m_Data;
    }

    public abstract double getClassification();

    public abstract double getPredictedClassification();

     public abstract void setPredictedClassification(double pPredictedClassification);    

    public abstract svm_node[] getNodes();

    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        int classif = (int)getClassification();

        sb.append(Integer.toString(classif));
        svm_node[] svm_nodes = getNodes();
        for (int i = 0; i < svm_nodes.length; i++) {
            svm_node node = svm_nodes[i];
            sb.append(" ");
            sb.append(nodeToString(node));
        }
        return sb.toString();

    }

    public static String nodeToString(svm_node s) {
         StringBuilder sb = new StringBuilder();
         sb.append(s.index);
         sb.append(":");
         sb.append(s.value);
         return sb.toString();
     }


}
